import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { IMenubarList } from '/@/type/store/layout'

const components:IObject<() => Promise<typeof import('*.vue')>> = {
    Layout: (() => import('/@/layout/index.vue')) as unknown as () => Promise<typeof import('*.vue')>,
    Redirect: (() => import('/@/layout/redirect.vue')) as unknown as () => Promise<typeof import('*.vue')>,
    LayoutBlank: (() => import('/@/layout/blank.vue')) as unknown as () => Promise<typeof import('*.vue')>,
    404: (() => import('/@/views/ErrorPage/404.vue')) as unknown as () => Promise<typeof import('*.vue')>,
    // Workplace: (() => import('/@/views/Dashboard/Workplace.vue')) as unknown as () => Promise<typeof import('*.vue')>,
    Login: (() => import('/@/views/User/Login.vue')) as unknown as () => Promise<typeof import('*.vue')>
}

//需要判定权限的路由 ()
export const GenerateRouter :Array<IMenubarList> = [
    {
        id:1,
        parentId:0,
        name: 'App',
        path: '/App',
        component: components['Layout'],
        redirect: '/App/AppList',
        meta: { title: '应用管理', icon: 'el-icon-eleme'},
    },
    {
        id:10,
        parentId:1,
        name: 'AppList',
        path: '/App/AppList',
        component: (() => import('../views/App/AppList.vue')) as unknown as () => Promise<typeof import('*.vue')>,
        meta: { title: '应用管理', icon: 'el-icon-menu' }
    },
    {
        id: 3,
        parentId: 0,
        name: 'Nav',
        path: '/Nav',
        component: components['Layout'],
        redirect: '/Nav/SecondNav/ThirdNav',
        meta: { title: '多级导航', icon: 'el-icon-picture', alwaysShow: true  }
    },
    {
        id: 30,
        parentId: 3,
        name: 'SecondNav',
        path: '/Nav/SecondNav',
        redirect: '/Nav/SecondNav/ThirdNav',
        component: 'SecondNav',
        meta: { title: '二级导航', icon: 'el-icon-camera', alwaysShow: true }
    },
    {
        id: 300,
        parentId: 30,
        name: 'ThirdNav',
        path: '/Nav/SecondNav/ThirdNav',
        component: 'ThirdNav',
        meta: { title: '三级导航', icon: 'el-icon-s-platform', alwaysShow: true  }
    },
    {
        id: 31,
        parentId: 3,
        name: 'SecondText',
        path: '/Nav/SecondText',
        redirect: '/Nav/SecondText/ThirdText',
        component: 'SecondText',
        meta: { title: '二级导航2', icon: 'el-icon-s-opportunity', alwaysShow: true }
    },
    {
        id: 310,
        parentId: 31,
        name: 'ThirdText',
        path: '/Nav/SecondText/ThirdText',
        component: 'ThirdText',
        meta: { title: '三级导航2', icon: 'el-icon-menu' }
    },
    {
        id: 5,
        parentId: 0,
        name: 'Permission',
        path: '/Permission',
        component: 'Layout',
        redirect: '/Permission/Directive',
        meta: { title: '权限管理', icon: 'el-icon-phone', alwaysShow: true }
    },
    {
        id: 50,
        parentId: 5,
        name: 'Directive',
        path: '/Permission/Directive',
        component: 'Directive',
        meta: { title: '指令管理', icon: 'el-icon-goods' }
    }
]

const websocketManageRouter:Array<IMenubarList> = [
    {
        name: 'homenum',
        path: '/',
        component: components['Layout'],
        redirect: '/Main/MainList',
        meta: { title: '控制台', icon: 'el-icon-eleme' ,hidden:true},
    },
    {
        name: 'Dashboard',
        path: '/Dashboard',
        component: components['Layout'],
        redirect: '/Dashboard/Workplace',
        meta: { title: '控制台', icon: 'el-icon-eleme' },
        children: [
            {
                name: 'Workplace',
                path: '/Dashboard/Workplace',
                component: (() => import('/@/views/Dashboard/Workplace.vue')) as unknown as () => Promise<typeof import('*.vue')>,
                meta: { title: '控制台', icon: 'el-icon-s-tools' }
            }
        ]
    }
   
]
// 静态路由页面
export const allowRouter:Array<IMenubarList> = [
    ...websocketManageRouter,
    {
        name: 'ErrorPage',
        path: '/ErrorPage',
        meta: { title: '错误页面', hidden: true, icon: 'el-icon-eleme' },
        component: components.LayoutBlank,
        redirect: '/ErrorPage/404',
        children: [
            {
                name: '404',
                path: '/ErrorPage/404',
                component: components['404'],
                meta: { title: '404', icon: 'el-icon-s-tools' }
            }
        ]
    },
    {
        name: 'RedirectPage',
        path: '/redirect',
        component: components['Layout'],
        meta: { title: '重定向页面', icon: 'el-icon-eleme', hidden: true },
        children: [
            {
                name: 'Redirect',
                path: '/redirect/:pathMatch(.*)*',
                meta: {
                    title: '重定向页面',
                    icon: ''
                },
                component: components.Redirect
            }
        ]
    },
    {
        name: 'Login',
        path: '/Login',
        component: components.Login,
        meta: { title: '登录', icon: 'el-icon-eleme', hidden: true }
    }
]

const router = createRouter({
    history: createWebHashHistory(), // createWebHistory
    routes: allowRouter as RouteRecordRaw[]
})

export default router